from django import http
from django.shortcuts import render, redirect

# Create your views here.
from django.views import View

from areas.models import Area


class AreasView(View):
    def get(self,request):
        try:
            areas = Area.objects.all()
            print(areas)
        except:
            return http.JsonResponse({'errno': 4001, 'errmsg': '数据库访问出错'})
        areas_li = []
        for area in areas:
            areas_li.append({
                'aid': area.id,
                'aname': area.name
            })

        result = {
            'errno': 0,
            'errmsg': 'OK',
            'data':areas_li
        }

        return http.JsonResponse(result)


class SearchView(View):
    def get(self, request):

        return redirect('/static/html/search.html')